import "@babel/polyfill";
import "url-polyfill";
import dva from "dva";

// import createHistory from 'history/createHashHistory';
// user BrowserHistory
import createHistory from "history/createBrowserHistory";
import createLoading from "dva-loading";
import "moment/locale/zh-cn";
import "./rollbar";

import "./index.less";
// 1. Initialize
const app = dva({
  history: createHistory()
});

// 2. Plugins
app.use(createLoading());

// 3. Register global model
app.model(require("./models/global").default);

// 4. Router
app.router(require("./router").default);

// 5. Start
app.start("#root");

export default app._store; // eslint-disable-line

function getParameterByName(name, url) {
  if (!url) {
    url = window.location.href;
  }
  name = name.replace(/[\\[\]]/g, "\\$&");
  var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
    results = regex.exec(url);
  if (!results) return null;
  if (!results[2]) return "";
  return decodeURIComponent(results[2].replace(/\\+/g, " "));
}

var userName = document.getElementById("userName");
if (userName) userName.value = getParameterByName("userName");

var password = document.getElementById("password");
if (password) password.value = getParameterByName("password");
